import BScroll from '@better-scroll/core'
import Slide from '@better-scroll/slide'
import { onMounted, onUnmounted, ref } from 'vue'
// 注册插件
BScroll.use(Slide)
export default function () {
  const slider = ref(null)
  const currentpage = ref(0)
  // 轮播图外层容器
  const sliderwrap = ref(null)
  onMounted(() => {
    slider.value = new BScroll(sliderwrap.value, {
      scrollX: true,
      scrollY: false,
      momentum: false,
      bounce: false,
      probeType: 2,
      slide: true
    })
    slider.value.on('slideWillChange', (page) => {
      currentpage.value = page.pageX
    })
  })
  onUnmounted(() => {
    slider.value.destroy()
  })
  return { currentpage, sliderwrap }
}
